package com.carrent.demo.Service.Impl;

import com.carrent.demo.Domain.UserContract;
import com.carrent.demo.Domain.Users;
import com.carrent.demo.Mapper.ContractMapper;
import com.carrent.demo.Mapper.UsersMapper;
import com.carrent.demo.Service.UsersService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;


@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    UsersMapper usersMapper;

    @Autowired
    ContractMapper contractMapper;

    @Override
    public List<Users> getPage(Integer start, Integer pageSize, String name) {
        final List<Users> page = usersMapper.getPage(start, pageSize, name);
        return page;
    }



    @Override
    public Integer getCount(String name) {
       return usersMapper.getCount(name);
    }

    @Override
    public Boolean deleteUser(String id) {

        contractMapper.deleteUserCompliter(Integer.parseInt(id));
        contractMapper.deleteUser(Integer.parseInt(id));
        final Boolean aBoolean = usersMapper.deleteUser(id);
        return  aBoolean;
    }

    @Override
    public Boolean editUser(Users users) {
        final Boolean aBoolean = usersMapper.editUser(users);
        return aBoolean;
    }

    @Override
    public Boolean addUser(Users users) {
        Random random = new Random();
        String result="";
        for (int i=0;i<6;i++)
        {
            result+=random.nextInt(10);
        }
        users.setAccount(result);
        final Boolean aBoolean = usersMapper.addUser(users);
        return  aBoolean;
    }

    @Override
    public Users login(String account) {
        return usersMapper.login(account);
    }
}
